package main;

import java.util.ArrayList;
import dbdao.*;
import items.*;

public class UpdateImg 
{
	int index;
	ArrayList<String> lTable;
	ArrayList<String> lPatron;
	ArrayList<LString> lResp;
	DBaseManager dbm;
	
	public UpdateImg()
	{
		lTable = new ArrayList<String>();
		lTable.add("reflex");
		lTable.add("fotos");
		
		lPatron = new ArrayList<String>();
		lPatron.add("");
		lPatron.add("");
		
		dbm = new DBaseManager();
		index = dbm.getLastIndex("img") +1;
		
		updateImg();
	}
	
	private void updateImg()
	{
		ArrayList<String> lSQL = new ArrayList<String>();
		for( int i=0 ; i<lTable.size() ; i++ )
		{
			int numElem = dbm.getLastIndex(lTable.get(i));
			for( int j=0 ; j<numElem ; j++ )
			{
				lSQL.add("UPDATE " + lTable.get(i) + " SET imgID=" + index + " WHERE id=" + j);
				lSQL.add("INSERT INTO img VALUES(" + index + ",'/images/"+lTable.get(i) + "/" + lPatron.get(i) + j + "')");
				//System.out.println("UPDATE " + lTable.get(i) + " SET imgID=" + index + " WHERE id=" + j);
				//System.out.println("INSERT INTO img VALUES(" + index + ",'/images/"+lTable.get(i) + "/" + lPatron.get(i) + j + "')");
				index++;
			}
		}
		dbm.updateElements(lSQL);
	}
}
